﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web;
using Project.Engine.Utilities;
using Project.Module.DAO.BL;

namespace Project.Module.Controller
{
    public class RegAccountController { }

    public partial class HomeController
    {
        [AcceptVerbs(HttpVerbs.Post)]
        public JsonResult RegAccount(string name, string email, string address, string city, string phoneHome, string mobile, string pass, string auPass)
        {
            if (MailUtil.CheckValidMail(email) == true) {
                // check account
                bool check = (new CustomerBL()).CheckAccountCustomer(name);
                if (check == true) {
                    // insert
                    (new CustomerBL()).InsertCustomer(name, email, address, mobile, pass);
                } else {
                    // return
                    return Json(new { result = 2 }, JsonRequestBehavior.AllowGet);  // username da co nguoi dang ki
                }
               
                // return
                return Json(new { result = 0 }, JsonRequestBehavior.AllowGet);  // dang ki thanh cong
            }

            // return
            return Json(new { result = 1 }, JsonRequestBehavior.AllowGet); // email ko dung dinh dang
        }
    }
}
